#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import unittest
from io import StringIO


class StringIOTest(unittest.TestCase):
    '''
    测试StringIO 读
    '''

    def test_read(self):
        with StringIO('Hello!\nHi!\nGoodbye!') as re:
            while True:
                s = re.readline()
                if s == '':
                    break
                print(s.strip())

    '''
    测试StringIO写
    '''

    def test_write(self):
        with StringIO() as wr:
            print(wr.write('123'))  # 3
            print(wr.getvalue())  # '123'


if __name__ == '__main__':
    unittest.main()
